package com.tongjie.hotelbooking.order.entity;

import com.tongjie.hotelbooking.checkinperson.entity.CheckInPerson;
import com.tongjie.hotelbooking.order.enums.OrderStatus;
import com.tongjie.hotelbooking.user.entity.User;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@Builder
@Entity
@Table(name = "hb_order")
@AllArgsConstructor
@NoArgsConstructor
public class Order implements Serializable {
    private static final long serialVersionUID = -5769098576876635972L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 订单类型
     */
    @Column(length = 32)
    @Enumerated(EnumType.STRING)
    private OrderType orderType;

    /**
     * 订单号
     */
    @Column
    private String orderNumber;

    /**
     * 行政区
     */
    @Column
    private String region;

    /**
     * 酒店名称
     */
    @Column
    private String hotelName;

    /**
     * 入住日期
     */
    @Column
    @Temporal(value = TemporalType.TIMESTAMP)
    private Date plannedCheckInDate;

    /**
     * 退房日期
     */
    @Column
    @Temporal(value = TemporalType.TIMESTAMP)
    private Date plannedCheckOutDate;

    /**
     * 入住天数
     */
    @Column
    private Integer dayCount;

    /**
     * 单间预算
     */
    @Column
    private BigDecimal singleRoomBudget;

    /**
     * 房间信息
     */
    @OneToMany(mappedBy = "order")
    private List<RoomInfo> roomInfos = new ArrayList<>();

    /**
     * 房间数
     */
    @Column
    private Integer totalRoomCount;

    /**
     * 总人数
     */
    @Column
    private Integer totalPeopleCount;

    /**
     * 儿童人数
     */
    @Column
    private Integer kidCount;

    /**
     * 额外餐饮消费预算
     */
    @Column BigDecimal additionalBudget;

    /**
     * 总预算
     */
    @Column
    private BigDecimal totalBudget;

    /**
     * 是否需要早餐
     */
    @Column
    private Boolean needBreakfast = Boolean.FALSE;

    /**
     * 无烟房
     */
    @Column
    private Boolean noSmokingBreakfast = Boolean.FALSE;

    /**
     * 是否需要酒店提供发票
     */
    @Column
    private Boolean needHotelInvoice = Boolean.FALSE;

    /**
     * 最早到店时间
     */
    @Column
    @Temporal(TemporalType.TIME)
    private Date arriveTime;

    /**
     * 允许添加同住人
     */
    @Column
    private Boolean allowedHousemate = Boolean.FALSE;

    /**
     * 订单金额
     */
    @Column
    private BigDecimal amount;

    /**
     * 平台佣金
     */
    @Column
    private BigDecimal platformCommission;

    /**
     * 创建人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "create_user_id")
    private User createUser;

    /**
     * 创建时间
     */
    @Column
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;

    /**
     * 入住人
     */
    @OneToMany(mappedBy = "order", cascade = CascadeType.ALL)
    private List<CheckInPerson> checkInPeoples = new ArrayList<>();

    /**
     * 订单状态
     */
    @Enumerated(EnumType.STRING)
    @Column(length = 32)
    private OrderStatus orderStatus;

    /**
     * 被接单次数
     */
    @Column
    private Integer acceptCount = 0;

    /**
     * 咨询单
     */
    @OneToMany(mappedBy = "order")
    private List<OrderConsulting> orderConsultings = new ArrayList<>();

}
